import ajax from '@/utils/request'

// 文章_详情
const getArticleDetail = ({ id }) => {
  return ajax({
    url: '/v1_0/articles/' + id
  })
}
// 文章 - 关注作者
const followedUserAPI = ({ autId }) => {
  return ajax({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: autId
    }
  })
}
// 文章 - 关注作者
const unFollowedUserAPI = ({ artId }) => {
  return ajax({
    url: '/v1_0/user/followings/' + artId,
    method: 'DELETE'
  })
}
// 评论 - 点赞
const articleLikeAPI = ({ artId }) => {
  return ajax({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: artId
    }
  })
}
// 评论 - 取消点赞
const articleDisLikeAPI = ({ artId }) => {
  return ajax({
    url: '/v1_0/article/likings/' + artId,
    method: 'DELETE'
  })
}

// 评论 - 获取列表
const getCommentListAPI = ({ artId, offset = null, limit = 10 }) => {
  return ajax({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset,
      limit
    }
  })
}
// 评论 - 点赞
const commentLikingAPI = ({ comId }) => {
  return ajax({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target: comId
    }
  })
}
// 评论 - 取消点赞
const commentDisLikingAPI = ({ comId }) => {
  return ajax({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })
}
// 评论 - 发布
const sendCommentAPI = ({ artId, content }) => {
  return ajax({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content
    }
  })
}
export {
  getArticleDetail,
  followedUserAPI,
  unFollowedUserAPI,
  articleLikeAPI,
  articleDisLikeAPI,
  getCommentListAPI,
  commentLikingAPI,
  commentDisLikingAPI,
  sendCommentAPI
}
